package gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.ConferencePaper;
import model.ProgramChair;
import model.SubProgramChair;

/**
 * 
 * @author Darrion Harris
 * 
 * This class is a view for displaying and managing the
 * SubProgramChair's role operations.
 *
 */
public class SPCViewport extends JPanel{
	
	private static final long serialVersionUID = -5075133682615711568L;
	
	protected static final int WIDTH = BaseViewFrame.FRAME_WIDTH;
	protected static final int HEIGHT = BaseViewFrame.FRAME_HEIGHT;
	protected static final int ROW_HEIGHT = 30;
	
	protected static SubProgramChair my_subchair;
    protected static ProgramChair my_chair;
    protected static String my_current_user_name;
    
    private static Container my_container_panel = new ScrollPane();
    private static Container my_home_panel;
    private static Container my_assign_panel;
    private static Container my_rec_panel;
    private static JButton my_cancel_button;
    
    private static JLabel my_title = new JLabel();
    
    public SPCViewport(SubProgramChair the_subchair, ProgramChair the_chair, String userName)
    {
        my_subchair = the_subchair;
        my_current_user_name = userName;
        my_chair = the_chair;
        
        my_container_panel.setBackground(BaseViewFrame.BACKGROUND_COLOR);
	    Dimension d = new Dimension(WIDTH, HEIGHT - 150);
        my_container_panel.setPreferredSize(d);
        
        my_cancel_button = createCancelButton();
        
        loadPapersPanel();
        
        this.add(createHeaderPanel(), BorderLayout.NORTH);
        this.add(my_container_panel, BorderLayout.CENTER);
        this.setOpaque(false);
        }
    
    /**
     * 
     * @return the panel responsible for displaying the header
     * information for the current view
     * 
     */
    public JPanel createHeaderPanel() {
    	JPanel heading = new JPanel();
    	heading.setBackground(BaseViewFrame.BACKGROUND_COLOR);
		heading.setLayout(new BoxLayout(heading, BoxLayout.LINE_AXIS));
		heading.add(my_title);
		heading.add(Box.createRigidArea(new Dimension(WIDTH/2,50)));
		heading.add(my_cancel_button);
		heading.setOpaque(false);
		return heading;
    }
    
    /**
     * 
     * @return the cancel button
     */
	@SuppressWarnings("serial")
	private JButton createCancelButton() {
		JButton button = new JButton("CANCEL");
		button.addActionListener(new AbstractAction()
		{

			public void actionPerformed(final ActionEvent the_event)
			{
				SPCViewport.back();
			}
		});
		return button;
	}
	
	/**
	 * Loads the view for assigning reviewers to a conference paper.
	 * @param the_paper to assign reviewers to
	 */
	protected static void loadReviewersPanel(ConferencePaper the_paper){
		my_assign_panel = new SPCAvailableReviewersPanel(the_paper);
		my_title.setText("My Available Reviewers");
		my_cancel_button.setVisible(true);
    	my_container_panel.remove(my_container_panel.getComponents()[0]);
    	my_container_panel.add(my_assign_panel);
	}
	
	/**
	 * Loads the view containing a 
	 * list of all of the assigned Manususcripts.
	 */
	protected static void loadPapersPanel(){
		my_home_panel = new SPCAssignedPapersPanel();
		my_title.setText("My Assigned Recommendations");
		my_cancel_button.setVisible(false);
		if(my_container_panel.getComponents().length > 0){
			my_container_panel.remove(my_container_panel.getComponents()[0]);
		}
        my_container_panel.add(my_home_panel);
	}
	
	/**
	 * Loads the view for submitting a 
	 * recommendation for a conference paper
	 * @param the_paper to submmit a recommendation.
	 */
	protected static void loadRecommendationPanel(ConferencePaper the_paper){
		my_rec_panel = new SPCRecommendationPanel(the_paper);
		my_title.setText("Upload My Recommendation");
		my_cancel_button.setVisible(true);
    	my_container_panel.remove(my_container_panel.getComponents()[0]);
    	my_container_panel.add(my_rec_panel);
	}
	
	/**
	 * Handles the back action for the views.
	 */
	protected static void back(){
		my_container_panel.remove(my_container_panel.getComponents()[0]);
		my_title.setText("My Assigned Recommendations");
		my_cancel_button.setVisible(false);
		my_container_panel.add(my_home_panel);
	}

}
